package com.lili.collection.restful.enums;

import cn.hutool.core.text.CharSequenceUtil;
import lombok.Getter;

/**
 * 接口请求方式类型
 *
 * @author: lili
 * @since: 2023/3/9 15:42
 */
public enum RequestMethodType {
    /**
     * GET请求
     */
    GET("GET"),
    /**
     * POST请求
     */
    POST("POST"),
    /**
     * PUT请求
     */
    PUT("PUT"),
    /**
     * DELETE请求
     */
    DELETE("DELETE");

    @Getter
    private final String code;

    RequestMethodType(String code) {
        this.code = code;
    }

    /**
     * 获取接口类型枚举，忽略大小写
     * @param code code
     * @return 接口类型枚举
     */
    public static RequestMethodType codeOf(String code) {
        for (RequestMethodType value : RequestMethodType.values()) {
            if (CharSequenceUtil.equalsIgnoreCase(value.getCode(), code)) {
                return value;
            }
        }
        throw new IllegalArgumentException("暂不支持该请求类型");
    }

}
